using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using Newtonsoft.Json;
using ns20;

namespace ns16
{
	internal static class Class140
	{
		public const string string_0 = "$id";

		public const string string_1 = "$ref";

		public const string string_2 = "$type";

		public const string string_3 = "$value";

		public const string string_4 = "$values";

		public const string string_5 = "ShouldSerialize";

		public const string string_6 = "Specified";

		private const string string_7 = "System.ComponentModel.DataAnnotations.MetadataTypeAttribute, System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

		private static bool? nullable_0;

		private static bool? nullable_1;

		private static readonly Class179<object, Type> class179_0 = new Class179<object, Type>(smethod_9);

		private static readonly Class179<Type, Type> class179_1 = new Class179<Type, Type>(smethod_13);

		private static Type type_0;

		public static bool Boolean_0
		{
			[SecuritySafeCritical]
			get
			{
				if (!nullable_0.HasValue)
				{
					try
					{
						new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
						new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess).Demand();
						new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
						new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
						new SecurityPermission(PermissionState.Unrestricted).Demand();
						nullable_0 = true;
					}
					catch (Exception)
					{
						nullable_0 = false;
					}
				}
				return nullable_0.Value;
			}
		}

		public static bool Boolean_1
		{
			get
			{
				if (!nullable_1.HasValue)
				{
					AppDomain currentDomain = AppDomain.CurrentDomain;
					nullable_1 = currentDomain.IsHomogenous && currentDomain.IsFullyTrusted;
				}
				return nullable_1.Value;
			}
		}

		public static Class167 Class167_0
		{
			get
			{
				if (Boolean_0)
				{
					return Class168.class168_0;
				}
				return Class170.Class167_0;
			}
		}

		public static JsonContainerAttribute smethod_0(Type type_1)
		{
			return Class141<JsonContainerAttribute>.smethod_0(type_1);
		}

		public static JsonObjectAttribute smethod_1(Type type_1)
		{
			return smethod_0(type_1) as JsonObjectAttribute;
		}

		public static JsonArrayAttribute smethod_2(Type type_1)
		{
			return smethod_0(type_1) as JsonArrayAttribute;
		}

		public static JsonDictionaryAttribute smethod_3(Type type_1)
		{
			return smethod_0(type_1) as JsonDictionaryAttribute;
		}

		public static SerializableAttribute smethod_4(Type type_1)
		{
			return Class141<SerializableAttribute>.smethod_0(type_1);
		}

		public static DataContractAttribute smethod_5(Type type_1)
		{
			Type type = type_1;
			DataContractAttribute dataContractAttribute;
			while (true)
			{
				if (type != null)
				{
					dataContractAttribute = Class141<DataContractAttribute>.smethod_0(type);
					if (dataContractAttribute != null)
					{
						break;
					}
					type = type.smethod_6();
					continue;
				}
				return null;
			}
			return dataContractAttribute;
		}

		public static DataMemberAttribute smethod_6(MemberInfo memberInfo_0)
		{
			if (memberInfo_0.smethod_1() == MemberTypes.Field)
			{
				return Class141<DataMemberAttribute>.smethod_0(memberInfo_0);
			}
			PropertyInfo propertyInfo = (PropertyInfo)memberInfo_0;
			DataMemberAttribute dataMemberAttribute = Class141<DataMemberAttribute>.smethod_0(propertyInfo);
			if (dataMemberAttribute == null && propertyInfo.smethod_0())
			{
				Type type = propertyInfo.DeclaringType;
				while (dataMemberAttribute == null && type != null)
				{
					PropertyInfo propertyInfo2 = (PropertyInfo)Class195.smethod_34(type, propertyInfo);
					if (propertyInfo2 != null && propertyInfo2.smethod_0())
					{
						dataMemberAttribute = Class141<DataMemberAttribute>.smethod_0(propertyInfo2);
					}
					type = type.smethod_6();
				}
			}
			return dataMemberAttribute;
		}

		public static MemberSerialization smethod_7(Type type_1, bool bool_0)
		{
			JsonObjectAttribute jsonObjectAttribute = smethod_1(type_1);
			if (jsonObjectAttribute != null)
			{
				return jsonObjectAttribute.MemberSerialization;
			}
			DataContractAttribute dataContractAttribute = smethod_5(type_1);
			if (dataContractAttribute != null)
			{
				return MemberSerialization.OptIn;
			}
			if (!bool_0)
			{
				SerializableAttribute serializableAttribute = smethod_4(type_1);
				if (serializableAttribute != null)
				{
					return MemberSerialization.Fields;
				}
			}
			return MemberSerialization.OptOut;
		}

		private static Type smethod_8(object object_0)
		{
			return class179_0.method_0(object_0);
		}

		private static Type smethod_9(object object_0)
		{
			return smethod_17<JsonConverterAttribute>(object_0)?.ConverterType;
		}

		public static JsonConverter smethod_10(object object_0, Type type_1)
		{
			Type type = smethod_8(object_0);
			if (type != null)
			{
				return JsonConverterAttribute.smethod_0(type);
			}
			return null;
		}

		public static TypeConverter smethod_11(Type type_1)
		{
			return TypeDescriptor.GetConverter(type_1);
		}

		private static Type smethod_12(Type type_1)
		{
			return class179_1.method_0(type_1);
		}

		private static Type smethod_13(Type type_1)
		{
			Type type = smethod_14();
			if (type == null)
			{
				return null;
			}
			object obj = type_1.GetCustomAttributes(type, inherit: true).SingleOrDefault();
			if (obj == null)
			{
				return null;
			}
			Interface14 @interface = (Boolean_0 ? Class164.smethod_5<Interface14>(obj) : new Class142(obj));
			return @interface.Type_0;
		}

		private static Type smethod_14()
		{
			if (type_0 == null)
			{
				Type type = Type.GetType("System.ComponentModel.DataAnnotations.MetadataTypeAttribute, System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
				if (!(type != null))
				{
					return null;
				}
				type_0 = type;
			}
			return type_0;
		}

		private static T smethod_15<T>(Type type_1) where T : Attribute
		{
			Type type = smethod_12(type_1);
			T val;
			if (type != null)
			{
				val = Class195.smethod_30<T>(type, bool_0: true);
				if (val != null)
				{
					return val;
				}
			}
			val = Class195.smethod_30<T>(type_1, bool_0: true);
			if (val != null)
			{
				return val;
			}
			Type[] interfaces = type_1.GetInterfaces();
			int num = 0;
			while (true)
			{
				if (num < interfaces.Length)
				{
					Type object_ = interfaces[num];
					val = Class195.smethod_30<T>(object_, bool_0: true);
					if (val != null)
					{
						break;
					}
					num++;
					continue;
				}
				return null;
			}
			return val;
		}

		private static T smethod_16<T>(MemberInfo memberInfo_0) where T : Attribute
		{
			Type type = smethod_12(memberInfo_0.DeclaringType);
			T val;
			if (type != null)
			{
				MemberInfo memberInfo = Class195.smethod_34(type, memberInfo_0);
				if (memberInfo != null)
				{
					val = Class195.smethod_30<T>(memberInfo, bool_0: true);
					if (val != null)
					{
						return val;
					}
				}
			}
			val = Class195.smethod_30<T>(memberInfo_0, bool_0: true);
			if (val != null)
			{
				return val;
			}
			if (memberInfo_0.DeclaringType != null)
			{
				Type[] interfaces = memberInfo_0.DeclaringType.GetInterfaces();
				foreach (Type type_ in interfaces)
				{
					MemberInfo memberInfo2 = Class195.smethod_34(type_, memberInfo_0);
					if (memberInfo2 != null)
					{
						val = Class195.smethod_30<T>(memberInfo2, bool_0: true);
						if (val != null)
						{
							return val;
						}
					}
				}
			}
			return null;
		}

		public static T smethod_17<T>(object object_0) where T : Attribute
		{
			Type type = object_0 as Type;
			if (type != null)
			{
				return smethod_15<T>(type);
			}
			MemberInfo memberInfo = object_0 as MemberInfo;
			if (memberInfo != null)
			{
				return smethod_16<T>(memberInfo);
			}
			return Class195.smethod_30<T>(object_0, bool_0: true);
		}
	}
}
